package com.jeecms.wicool.manager.shops.impl;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.jeecms.cms.entity.main.CmsUser;
import com.jeecms.common.hibernate3.Updater;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.shops.WiPayTypeDao;
import com.jeecms.wicool.entity.shops.PayType;
import com.jeecms.wicool.manager.shops.WiPayTypeMng;

@Service
@Transactional
public class WiPayTypeMngImpl implements WiPayTypeMng {
	
	private WiPayTypeDao dao;
	@Autowired
	public void setDao(WiPayTypeDao dao) {
		this.dao = dao;
	}
	
	@Transactional(readOnly = true)
	public Pagination getPage(int pageNo, int pageSize,CmsUser user) {
		Pagination page = dao.getPage(pageNo, pageSize,user);
		return page;
	}
	@Override
	public PayType findById(Integer id) {
		PayType entity = dao.findById(id);
		return entity;
	}

	@Override
	public PayType update(PayType bean) {
		Updater<PayType> updater = new Updater<PayType>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}

	@Override
	public PayType save(PayType bean) {
		dao.save(bean);
		return bean;
	}

	@Override
	public PayType deleteById(Integer id) {
		PayType bean = dao.deleteById(id);
		return bean;
	}

	@Override
	public PayType[] deleteByIds(Integer[] ids) {
		PayType[] beans = new PayType[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}
	@Override
	public boolean payTypeNotExist(String shopId,String payType) {
		//获取当前店铺id已经存在的支付方式
		List<PayType> list = dao.getPayTypeList(Integer.parseInt(shopId));
		for(PayType p :list){
			if(p.getPayType().equals(payType)){
				return false;
			}
		}
		return true;
	}

	@Override
	public List<PayType> getPayTypeList(Integer shopId) {
		return dao.getPayTypeList(shopId);
	}

}